<template>
	<view style="background: #FFFFFF;min-height: 100vh;">
		<view class="detail">
			<rich-text :nodes="html"></rich-text>
		</view>
		<view v-if="showModal" :class="modalName=='Image'?'show cu-modal':'cu-modal'">
			<view class="cu-dialog">
				<!-- style="background-image: url('https://ossweb-img.qq.com/images/lol/web201310/skin/big91012.jpg');height:700upx;background-size:cover;" -->
				<view class="bg-img" :style="{backgroundImage:'url('+imgUrl+')',backgroundSize:'100% auto'}">
					<view class="cu-bar justify-end text-white">
						<view class="action"  @click="hideModal">
							<text class="cuIcon-close" style="background: #333333;border-radius: 50%;"></text>
						</view>
					</view>
				</view>
				<view class="cu-bar bg-white">
					<view class="action margin-0 flex-sub  solid-left" @click="toFlooringPage">前往查看</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const globalData = getApp().globalData;
	const httpurl = globalData.global_url + "/link/detail";
	const getWebSrcURL = globalData.global_url + "/link/landpage"
	export default {
		data() {
			return {
				webViewLink: '',
				modalName: 'Image',
				html: '',
				showModal: false,
				id: '',
				imgUrl: ''
			}
		},
		onLoad(options) {
			console.log('detail-options', options)
			uni.showLoading({
				title:'加载中...'
			})
			this.id = options.linkid
			this.getLinkDetail()
			this.getWebSrc()
		},
		methods: {
			toFlooringPage() {
				uni.navigateTo({
					url: '/pages/flooringPage/flooringPage?webviewsrc=' + this.webViewLink
				})
			},
			hideModal() {
				this.modalName = ''
			},
			getLinkDetail() {
				let params = {
					link_id: this.id
				}
				uni.request({
					url: httpurl,
					data: params
				}).then(data => {
					var [error, res] = data;
					console.log(res.data);
					if (res.data.errno === '000') {
						this.html = res.data.result.text
						
						uni.setNavigationBarTitle({
							title: res.data.result.title
						})
						// this.webViewLink = res.data.result.linik_url
						this.imgUrl = `https://ms.hdyhlz.com/${res.data.result.thumb_picture}`
					}
					uni.hideLoading()
				}).catch(err => {
					uni.hideLoading()
					console.log(err)
				})
			},
			getWebSrc() {
				let params = {
					time: Date.parse(new Date())
				}
				uni.request({
					url: getWebSrcURL,
					data: params
				}).then(data => {
					var [error, res] = data;
					console.log(res.data);
					if (res.data.errno === '000') {
						this.showModal = true
						this.webViewLink = res.data.result.loadurl
						this.imgUrl = `https://ms.hdyhlz.com/${res.data.result.thumb_picture}`
					}
				}).catch(err => {
					console.log(err)
				})
			}
		}
	}
</script>

<style>
	.detail {
		width: 95%;
		margin: 0 auto;
		padding: 10upx 0;
	}

	.cu-dialog {
		width: 80%;
	}

	.bg-img {
		height: 700upx;
	}
</style>
